import os


class Config:
    # 基础配置
    DEBUG = True  # 开发环境设为True，生产环境设为False
    HOST = '0.0.0.0'  # 允许所有IP访问
    PORT = 5000  # 默认端口

    # 数据库配置
    MYSQL_HOST = 'localhost'  # Docker服务名
    MYSQL_USER = 'root'  # 与docker-compose.yml中配置的用户名一致
    MYSQL_PASSWORD = 'm6913602'  # 与docker-compose.yml中配置的密码一致
    MYSQL_DB = 'gesture_db'

    # SQLAlchemy配置
    SQLALCHEMY_DATABASE_URI = f'mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}/{MYSQL_DB}?charset=utf8mb4&connect_timeout=10'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ENGINE_OPTIONS = {
        'pool_recycle': 3600,
        'pool_pre_ping': True,
        'pool_timeout': 30
    }

    # Redis配置
    REDIS_HOST = 'localhost'  # Docker服务名
    REDIS_PORT = 6379
    REDIS_DB = 0
    REDIS_PASSWORD = None  # 如果有密码，请设置
    REDIS_URL = f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}'
    
    # Redis缓存配置
    CACHE_TYPE = 'redis'
    CACHE_REDIS_HOST = REDIS_HOST
    CACHE_REDIS_PORT = REDIS_PORT
    CACHE_REDIS_DB = REDIS_DB
    CACHE_REDIS_PASSWORD = REDIS_PASSWORD
    CACHE_DEFAULT_TIMEOUT = 3600  # 默认缓存时间1小时

    # 会话安全密钥
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-secret-key-please-change-in-production'

    # 其他可选配置
    UPLOAD_FOLDER = 'uploads'
    MAX_CONTENT_LENGTH = 16 * 1024 * 1024  # 16MB文件上传限制

    # Flask-Login 配置
    REMEMBER_COOKIE_DURATION = 3600  # 记住登录状态1小时
    REMEMBER_COOKIE_SECURE = False    # 开发环境设为False
    REMEMBER_COOKIE_HTTPONLY = True  # 防止JavaScript访问cookie
    SESSION_COOKIE_SECURE = False     # 开发环境设为False
    SESSION_COOKIE_HTTPONLY = True   # 防止JavaScript访问session cookie